home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / diary_note / journal / !Journal / DatePick (.txt) < prev    next >
Encoding:
RISC OS BBC BASIC V Source  |  1995-02-09  |  9.3 KB  |  238 lines

  1.  Module DatePick
  2.  -----------------------------------------------------------------------
  3.  DatePick Handling Routines
  4.  -----------------------------------------------------------------------
  5.  Public Methods Supported:
  6.    shell_DatePick_Init         Initialises module
  7.    shell_DatePickerOpen        Opens the DatePick DBox
  8.    shell_AttachPopupDatePicker Attaches the DatePicker to a window/icon
  9.  Private Methods Supported:
  10.    DatePicker_PreOpen
  11.    DatePicker_Selection
  12.    _DatePicker_BumpHandler
  13.    _DatePicker_BumpHandler2
  14.    _DatePicker_DecodeDate
  15.    _DatePicker_Click
  16.  Message Strings required by module
  17.    monthstr
  18.    daystr
  19.    today
  20. "*|Start FN_shell_DatePick_Init
  21. _shell_DatePickInit
  22.  Define Constants
  23.  EDATEPICK_TODAYICON%        = 0            : 
  24.  Default action icon
  25. !TDATEPICK_FIRSTICON%        = 11           : 
  26.  First icon that holds a day number
  27. "TDATEPICK_LASTICON%         = 53           : 
  28.  Last  icon that holds a day number
  29. #SDATEPICK_MONTHICON%        = 1            : 
  30.  Icon handle of month display icon
  31. $RDATEPICK_MONTHINC%         = 3            : 
  32.  Icon handle month increment icon
  33. %RDATEPICK_MONTHDEC%         = 4            : 
  34.  Icon handle month decrement icon
  35. &PDATEPICK_YEARICON%         = 2            : 
  36.  Icon handle year  display icon
  37. 'QDATEPICK_YEARINC%          = 55           : 
  38.  Icon handle year increment icon
  39. (QDATEPICK_YEARDEC%          = 54           : 
  40.  Icon handle year decrement icon
  41. )PDATEPICK_FIRSTWEEKDAYICON% = 5            : 
  42.  Icon handle first weekday icon
  43. +EDATEPICK_ESG%              = 1            : 
  44.  ESG of day nr icons
  45. ,GDATEPICK_SEP$              = "."          : 
  46.  Date seperater string
  47. -EDATEPICK_WINDOWNAME$       = "datepicker" : 
  48.  Template identifier
  49.  Define variables
  50. 0=G_DatePick_DBoxHandle%     = -1    : 
  51.  DBox window handle
  52. 1HG_DatePick_NextIcon%       = -1    : 
  53.  Next icon that needs updating
  54. 2CG_DatePick_DBox_Updated%   = 
  55.  TRUE when DBox is up-to-date
  56. 3FG_DatePick_DBox_Created%   = 
  57.  TRUE when DBox has been created
  58. 4_G_DatePick_NotifyFN$       = ""    : 
  59.  FN to call when selection is made in datepicker dbox
  60. 5SG_DatePick_WindowHandle%   = -1    : 
  61.  Handle of window containing display icon
  62. 6XG_DatePick_DisplayIcon%    = -1    : 
  63.  Handle of icon to display resulting selection
  64. 7#G_DatePick_CurrDay%        = -1
  65. 8#G_DatePick_CurrMonth%      = -1
  66. 9#G_DatePick_CurrYear%       = -1
  67. =#*|extract FN_DatePicker_PreOpen
  68. >'*|extract FN_DatePicker_BumpHandler
  69. ?(*|extract FN_DatePicker_BumpHandler2
  70. @&*|extract FN_DatePicker_DecodeDate
  71. A!*|extract FN_DatePicker_Click
  72. B-*|extract PROCshell_AttachPopupDatePicker
  73. D *|Stop FN_shell_DatePickInit
  74. H$*|Start PROCshell_DatePickerOpen
  75. *|!PROCshell_DatePickerOpen
  76. K8*|!Opens the datepicker dbox and calls the specified
  77. L(*|!routine when a selection is made.
  78. shell_DatePickerOpen( window_handle%, display_icon%, menu_icon%, notify_FN$ )
  79. O-G_DatePick_WindowHandle% = window_handle%
  80. P,G_DatePick_DisplayIcon%  = display_icon%
  81. Q)G_DatePick_NotifyFN$     = notify_FN$
  82. shell_OpenWindowDynamic( DATEPICK_WINDOWNAME$, "_DatePicker_PreOpen", "" )
  83. shell_WindowMoveToPopUpPos( window_handle%, menu_icon%, 
  84. shell_GetDynamicWindowHandle )
  85. V#*|Stop PROCshell_DatePickerOpen
  86. Z!*|Start FN_DatePicker_PreOpen
  87. _DatePicker_PreOpen( window_handle% )
  88.  loop%,monthstr$, daystr$
  89. _+G_DatePick_DBoxHandle% = window_handle%
  90.  "XHourglass_On"
  91.  Fill in weekday names..
  92.  loop% = 0 
  93. shell_IconPutData( G_DatePick_DBoxHandle%, DATEPICK_FIRSTWEEKDAYICON% + loop%, 
  94. shell_CalendarWeekDayString( loop% + 1 ), 
  95.  loop%
  96.  And 'Today' button..
  97. shell_IconPutData( G_DatePick_DBoxHandle%, DATEPICK_TODAYICON%, 
  98. shell_MessageNoArgs( "today" ), 
  99. shell_AttachClickSelect( G_DatePick_DBoxHandle%, -1, "_DatePicker_Click" )
  100. shell_AttachHelpTag( G_DatePick_DBoxHandle%, -1, "dpwin" )
  101. shell_CalendarGetTodaysDate( G_DatePick_CurrDay% , G_DatePick_CurrMonth% , G_DatePick_CurrYear% )
  102. shell_DatePickerCreateCalendar( G_DatePick_CurrDay%, G_DatePick_CurrMonth% , G_DatePick_CurrYear% )
  103. shell_AttachBumpHandler( G_DatePick_DBoxHandle%, DATEPICK_MONTHICON%, DATEPICK_MONTHINC%, DATEPICK_MONTHDEC%, -9999, 9999, 1, 
  104. , "_DatePicker_BumpHandler" , "_DatePicker_DecodeDate" )
  105. shell_AttachBumpHandler( G_DatePick_DBoxHandle%, DATEPICK_YEARICON%, DATEPICK_YEARINC%, DATEPICK_YEARDEC%, -9999, 9999, 1, 
  106. , "_DatePicker_BumpHandler2" , "" )
  107.  "Hourglass_Off"
  108. x *|Stop FN_DatePicker_PreOpen
  109. |.*|Start PROCshell_DatePickerCreateCalendar
  110. shell_DatePickerCreateCalendar( day%, month%, year% )
  111.  day_of_week%, month_str$, day_nr%, start_icon%, days_in_month%
  112.  selected%
  113.  "Hourglass_On"
  114. B  days_in_month% = 
  115. shell_CalendarDaysInMonth( month%, year% )
  116. A  day_of_week% = 
  117. shell_CalendarDayOfWeek( 1, month%, year% )
  118. 7  month_str$ = 
  119. shell_CalendarMonthString( month% )
  120. shell_CloseWindow( G_DatePick_DBoxHandle% )
  121. shell_IconPutData( G_DatePick_DBoxHandle%, DATEPICK_YEARICON%,  
  122. ( year% ), 
  123. shell_IconPutData( G_DatePick_DBoxHandle%, DATEPICK_MONTHICON%, month_str$, 
  124. 7  start_icon%  = DATEPICK_FIRSTICON% + day_of_week%
  125.  Make first and last rows non-responsive to mouse clicks..
  126.  icon% = 1 
  127. Z    
  128. shell_IconSetButtonType( G_DatePick_DBoxHandle%, icon% + DATEPICK_FIRSTICON%, 0 )
  129. X    
  130. shell_IconPutData( G_DatePick_DBoxHandle%, icon% + DATEPICK_FIRSTICON%, "", 
  131. G    
  132. shell_IconPutData( G_DatePick_DBoxHandle%, icon% + 39, "", 
  133. I    
  134. shell_IconSetButtonType( G_DatePick_DBoxHandle%, icon% + 39, 0 )
  135. I    
  136. shell_IconSetButtonType( G_DatePick_DBoxHandle%, icon% + 46, 0 )
  137. G    
  138. shell_IconPutData( G_DatePick_DBoxHandle%, icon% + 46, "", 
  139.  icon%
  140.  Deselect any selected icons in the ESG
  141. T  selected% = 
  142. shell_IconRadioSelection( G_DatePick_DBoxHandle%, DATEPICK_ESG% )
  143.  selected% >= 0 
  144. shell_IconSet( G_DatePick_DBoxHandle%, selected%, 0 )
  145.  day_nr% = 1 
  146.  days_in_month%
  147. `    
  148. shell_IconPutData( G_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 
  149. ( day_nr% ), 
  150. X    
  151. shell_IconSetButtonType( G_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 3 )
  152. i    
  153.  day_nr% = G_DatePick_CurrDay% 
  154.  month% = G_DatePick_CurrMonth% 
  155.  year% = G_DatePick_CurrYear% 
  156. P      
  157. shell_IconSet( G_DatePick_DBoxHandle%, start_icon% + day_nr% - 1, 1 )
  158.         
  159.  day_nr%
  160. shell_OpenWindow( G_DatePick_DBoxHandle%, 
  161.  "Hourglass_Off"
  162. -*|Stop PROCshell_DatePickerCreateCalendar
  163. %*|Start FN_DatePicker_BumpHandler
  164. _DatePicker_BumpHandler( month%, button% )
  165.  year%
  166. Qyear% = 
  167. shell_IconGetData( G_DatePick_DBoxHandle%, DATEPICK_YEARICON% ) )
  168.  month% < 1 
  169.   year% -= 1
  170.   month% = 12
  171.  month% > 12 
  172.   year% += 1
  173.   month% = 1
  174. shell_DatePickerCreateCalendar( 1, month%, year% )
  175. shell_CalendarMonthString( month% )
  176. $*|Stop FN_DatePicker_BumpHandler
  177. &*|Start FN_DatePicker_BumpHandler2
  178. _DatePicker_BumpHandler2( year%, button% )
  179.  month%
  180. lmonth% = 
  181. shell_CalendarMonthNumber( 
  182. shell_IconGetData( G_DatePick_DBoxHandle%, DATEPICK_MONTHICON% ) )
  183. shell_DatePickerCreateCalendar( 1, month%, year% )
  184. ( year% )
  185. %*|Stop FN_DatePicker_BumpHandler2
  186. $*|Start FN_DatePicker_DecodeDate
  187. _DatePicker_DecodeDate( month$ )
  188. shell_CalendarMonthNumber( month$ )
  189. #*|Stop FN_DatePicker_DecodeDate
  190. *|Start FN_DatePicker_Click
  191. _DatePicker_Click( window_handle%, icon_handle% )
  192.  _date$, day%, month%, year%, offset%
  193.  icon_handle% > DATEPICK_FIRSTICON% 
  194.  icon_handle% < DATEPICK_LASTICON% 
  195. f  month% = 
  196. shell_CalendarMonthNumber( 
  197. shell_IconGetData( window_handle%, DATEPICK_MONTHICON% ) )
  198. `  _date$  = 
  199.  "0" + 
  200. shell_IconGetData( window_handle%, icon_handle% ), DATEPICK_YEARICON% )
  201. H  _date$ += DATEPICK_SEP$ + 
  202.  "0" + 
  203. ( month% ), 2 ) + DATEPICK_SEP$
  204. O  _date$ += 
  205. shell_IconGetData( window_handle%, DATEPICK_YEARICON% ), 2 )
  206. shell_CloseWindow( window_handle% )
  207. DatePicker_Selection( _date$ )
  208.  icon_handle% = 0 
  209. shell_CalendarGetTodaysDate( day% , month% , year% )
  210. 8  _date$  = 
  211.  "0" + 
  212. ( day%   ), 2 ) + DATEPICK_SEP$
  213. 8  _date$ += 
  214.  "0" + 
  215. ( month% ), 2 ) + DATEPICK_SEP$
  216. !  _date$ += 
  217. ( year% ), 2 )
  218. shell_CloseWindow( window_handle% )
  219. DatePicker_Selection( _date$ )
  220. *|Stop FN_DatePicker_Click
  221. $*|Start PROCDatePicker_Selection
  222. DatePicker_Selection( _date$ )
  223.  void%
  224.  G_DatePick_NotifyFN$ <> "" 
  225. ;  void% = 
  226. ( "FN" + G_DatePick_NotifyFN$ + "(_date$)" )
  227.  G_DatePick_DisplayIcon% >= 0 
  228. Z    
  229. shell_IconPutData( G_DatePick_WindowHandle%, G_DatePick_DisplayIcon%, _date$, 
  230. #*|Stop PROCDatePicker_Selection
  231.     +*|Start PROCshell_AttachPopupDatePicker
  232. shell_AttachPopupDatePicker( wh%, menuic%, dispic%, notify_fn$ )
  233. shell_WindowLoaded( DATEPICK_WINDOWNAME$ ) 
  234. shell_DoAttachPopupHandler( wh%, menuic%, dispic%, -1, notify_fn$, 2 )
  235.  99, 
  236. shell_MessageOneArg( "SHELLMSG37", DATEPICK_WINDOWNAME$ )
  237. **|Stop PROCshell_AttachPopupDatePicker
  238.